<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>

</head>
<body>
    <div id="app">
        <button-counter></button-counter>
        <button-counter></button-counter>
        <button-counter></button-counter>
    </div>

    <script>
        Vue.component("button-counter",{
            //如果不使用函数返回，复用的组件的data数据是相同的引用，通过函数的返回对象，每次创建的都是一个新的数据引用
            // data:{
            //     count:0
            // },
            data(){
                return {
                    count:0
                }
            },
            created(){
                console.log("我是组件");
                console.log(this);
            },
            template:`
            <button v-on:click="count++">你点击了{{count}}次</button>
            `
        })

        var app = new Vue({
            el:"#app",
            created(){
                console.log("我是根");
                console.log(this);
            },
        })

    </script>
</body>
</html>